from django.db import models

from apps.category.models import Category
from apps.user.models import User


class Foods(models.Model):
    """菜品数据"""
    name = models.CharField(max_length=50, verbose_name='名称')
    title = models.CharField(max_length=200, verbose_name='标题')

    default_image = models.CharField(max_length=200, default='', null=True, blank=True, verbose_name='默认图片')

    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    user = models.ForeignKey(User, default=1, on_delete=models.PROTECT, verbose_name='用户')
    viewCount = models.IntegerField(verbose_name="浏览人数", default=1)
    collect = models.IntegerField(verbose_name="收藏人数", default=1)

    class Meta:
        db_table = 'cp_foods'
        verbose_name = '菜品'
        verbose_name_plural = verbose_name


class DoSing(models.Model):
    """配料表数据"""
    name = models.CharField(max_length=50, verbose_name='配料名字')
    num = models.CharField(max_length=50, verbose_name='配料数量')

    food = models.ForeignKey(Foods, on_delete=models.PROTECT, verbose_name='从属类别')

    class Meta:
        db_table = 'cp_dosing'
        verbose_name = '菜品配料'
        verbose_name_plural = verbose_name


class MethodOfWork(models.Model):
    """做法表"""
    titles = models.CharField(max_length=200, verbose_name='做法步骤')
    default_image = models.CharField(max_length=200, default='', null=True, blank=True, verbose_name='默认图片')

    food = models.ForeignKey(Foods, on_delete=models.PROTECT, verbose_name='从属类别')
    sequence = models.IntegerField(verbose_name='做法顺序')

    class Meta:
        db_table = 'cp_method_of_work'
        verbose_name = '菜品做法'
        verbose_name_plural = verbose_name


# 菜品分类表
class FoodCategory(models.Model):
    food = models.ForeignKey(Foods, on_delete=models.PROTECT, verbose_name='菜品所属')
    category = models.ForeignKey(Category, on_delete=models.PROTECT, verbose_name='分类所属')

    class Meta:
        db_table = 'cp_food_category'
        verbose_name = '菜品分类'
        verbose_name_plural = verbose_name
